package com.ruoyi.web.controller.dormitory;

import java.util.List;

import com.ruoyi.dormitory.domain.DormitoryItems;
import com.ruoyi.dormitory.service.IDormitoryItemsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宿舍物品Controller
 * 
 * @author ruoyi
 * @date 2023-04-26
 */
@Controller
@RequestMapping("/dormitory/dormitoryItems")
public class DormitoryItemsController extends BaseController
{
    private String prefix = "dormitory/dormitoryItems";

    @Autowired
    private IDormitoryItemsService dormitoryItemsService;

    @RequiresPermissions("dormitory:dormitoryItems:view")
    @GetMapping()
    public String dormitoryItems()
    {
        return prefix + "/dormitoryItems";
    }

    /**
     * 查询宿舍物品列表
     */
    @RequiresPermissions("dormitory:dormitoryItems:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DormitoryItems dormitoryItems)
    {
        startPage();
        List<DormitoryItems> list = dormitoryItemsService.selectDormitoryItemsList(dormitoryItems);
        return getDataTable(list);
    }

    /**
     * 导出宿舍物品列表
     */
    @RequiresPermissions("dormitory:dormitoryItems:export")
    @Log(title = "宿舍物品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DormitoryItems dormitoryItems)
    {
        List<DormitoryItems> list = dormitoryItemsService.selectDormitoryItemsList(dormitoryItems);
        ExcelUtil<DormitoryItems> util = new ExcelUtil<DormitoryItems>(DormitoryItems.class);
        return util.exportExcel(list, "宿舍物品数据");
    }

    /**
     * 新增宿舍物品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存宿舍物品
     */
    @RequiresPermissions("dormitory:dormitoryItems:add")
    @Log(title = "宿舍物品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DormitoryItems dormitoryItems)
    {
        return toAjax(dormitoryItemsService.insertDormitoryItems(dormitoryItems));
    }

    /**
     * 修改宿舍物品
     */
    @RequiresPermissions("dormitory:dormitoryItems:edit")
    @GetMapping("/edit/{itemNumber}")
    public String edit(@PathVariable("itemNumber") Long itemNumber, ModelMap mmap)
    {
        DormitoryItems dormitoryItems = dormitoryItemsService.selectDormitoryItemsByItemNumber(itemNumber);
        mmap.put("dormitoryItems", dormitoryItems);
        return prefix + "/edit";
    }

    /**
     * 修改保存宿舍物品
     */
    @RequiresPermissions("dormitory:dormitoryItems:edit")
    @Log(title = "宿舍物品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DormitoryItems dormitoryItems)
    {
        return toAjax(dormitoryItemsService.updateDormitoryItems(dormitoryItems));
    }

    /**
     * 删除宿舍物品
     */
    @RequiresPermissions("dormitory:dormitoryItems:remove")
    @Log(title = "宿舍物品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dormitoryItemsService.deleteDormitoryItemsByItemNumbers(ids));
    }
}
